import type {
  PageResultProjectTemplateVO,
  ProjectTemplateVO,
  TemplatesSearchRequest,
} from "@/interface/project";
import request from "@/utils/request";
const mock = "https://m1.apifoxmock.com/m1/7176471-6900810-default";

// 项目类型接口
export interface ProjectType {
  id: string;
  name: string;
  // code?: string;
  // description?: string;
  // createTime?: string;
  // updateTime?: string;
}

// 生命周期接口
export interface Lifecycle {
  id: string;
  name: string;
  // code?: string;
  // description?: string;
  // createTime?: string;
  // updateTime?: string;
}

// 分页请求参数
export interface PageRequest {
  pageNo: number;
  pageSize: number;
  conditions?: any[];
  logic?: string;
  sortParams?: any[];
}

export interface ProjectTemplate {
  id: string;
  name: string;
  description: string;
  preview?: string;
  previewUrl?: string;
  type?: string;
  createTime?: string;
  updateTime?: string;
}

// 获取项目模板列表
export const getProjectTemplates = (params: TemplatesSearchRequest) => {
  return request<PageResultProjectTemplateVO>({
    url: `/projectTemplate/list`,
    method: "post",
    data: params,
  });
};

// 获取项目模板详情
export const getProjectTemplateDetail = (id: string) => {
  return request<ProjectTemplateVO>({
    url: `/projectTemplate/${id}`,
    method: "get",
  });
};

// 根据模板创建项目
export const createProjectFromTemplate = (projectData: any) => {
  return request({
    url: `/project/create`,
    method: "post",
    data: projectData,
  });
};

// 创建空白项目
export const createBlankProject = (projectData: any) => {
  return request({
    url: `/project/create-blank`,
    method: "post",
    data: projectData,
  });
};

// 获取项目类型列表
export const getProjectTypes = (params?: {
  pageNo: number;
  pageSize: number;
}) => {
  return request<{ result: ProjectType[]; total: number }>({
    url: `/projectType/list`,
    method: "post",
    data: params,
  });
};

// 获取生命周期列表
export const getLifecycles = (params?: {
  pageNo: number;
  pageSize: number;
}) => {
  return request<{ result: Lifecycle[]; total: number }>({
    url: `/lifecycle/list`,
    method: "post",
    data: params,
  });
};
